<template>
  <div class="pc-login_view">
    <div class="pc-login_view_header">
      <img
        src="@/assets/images/logo.png"
        class="pc-login_view_header_logo"
      />
      颐信巧思
    </div>
    <div class="pc-login_view_container">
      <div class="pc-login_view_container_form">
        <h3 class="pc-login_view_container_form_title">登录moodytiger系统</h3>
        <p class="pc-login_view_container_form_desc">点击以下任意系统进入</p>
        <div class="pc-login_view_container_form_item" @click="doLogin('pdm')">moodytiger PDM</div>
        <div class="pc-login_view_container_form_item" @click="doLogin('scm')">moodytiger SCM</div>
      </div>
    </div>
    <div class="pc-login_view_footer">
      <span class="pc-login_view_footer_powered">Powered by</span>
      <span class="pc-login_view_footer_name">颐信巧思</span>
      <img
        src="@/assets/images/icon1.png"
        class="pc-login_view_footer_icon"
      />
      <img
        src="@/assets/images/icon2.png"
        class="pc-login_view_footer_icon"
      />
    </div>
  </div>
</template>
<script setup>
import { useRoute } from 'vue-router';
import { getLogin, getScmLogin } from '@/api/user';

const route = useRoute();

const doLogin = (url) => {
  const list = JSON.parse(sessionStorage.getItem('sso'));
  const thirdId = url === 'pdm' ? '6522737a4c7d6516277a3c94' : 'scm';
  const item = list.find(item => item.thirdId === thirdId);
  if (!item) {
    message.error('权限不足');
    return;
  }
  const { realname, password } = item;
  if (url === 'pdm') {
    const params = {
      userName: realname,
      passWord: password,
      company: thirdId
    };
    getLogin(params).then(res => {
      let {
          message
        } = res;
        window.location.href = message;
    });
  } else {
    const params = {
      userName: realname,
      passWord: password,
      company: 1
    };
    getScmLogin(params).then(res => {
      let { sessionKey } = res;
      // setCookie('sessionKey', sessionKey, 24 * 60 * 60 * 1000);
      window.location.href = `http://202.105.104.158:8202/srm/main.html?key=${sessionKey}`;
      // window.location.href = `http://202.105.104.158:8189/srm/main.html?key=${sessionKey}`;
    });
  }
}
</script>
<style lang="less" scoped>
@import "./index.less";
</style>
